/******************************************************************************
* Copyright (C) 2020, BBI Technology Co.,Ltd All rights reserved.
*
* Author: caizhiwei.
*/
/******************************************************************************/
/** \file main_boot.c
 
 ******************************************************************************/
#include "bsp_flash.h"
#include "bsp_uart.h"
#include "iap.h"
#include "app_factory.h"
#include "bsp_timer.h"

uint8_t Boot_state =0;

int32_t main(void)
{	
 	IAP_UpdateCheck(&Boot_state);
    BSP_LPUARTx_Init(M0P_LPUART0, 2400, LPUartEven); 
	
	//运行到这里,说明
	//1. 需要升级: 从备份区拷贝固件到APP
	//2. 需要写表号	
	
	if(Boot_state == ready_api)
	{
		IAP_WriteFirmware2Flash(52); /* 26*1024 = 26KB */	  
		IAP_ChangeMode(jump2app); 	// 改写IAP标志位
		MCU_SoftRest();		
	}
		
	if(Boot_state == flash_wateraddr_empty)
	{
		BSP_Timer3_init(500);
		while(1)
		{
		   MbRxPoll();
		}
	}	
}


